#include "myImage.h"

myImage::myImage()
{
	//控件初始化
	openBtn = new QPushButton("打开");
	saveBtn = new QPushButton("保存");
	image.load("/cut.jpg");
	QHBoxLayout *hLay = new QHBoxLayout();
	hLay->addWidget(openBtn);
	hLay->addWidget(saveBtn);
	//布局
	QVBoxLayout *vLay = new QVBoxLayout();
	vLay->addLayout(hLay);
	QWidget *widget = new QWidget();
	widget->resize(500,500);
	vLay->addWidget(widget);
	//加载布局
	setLayout(vLay);
	resize(600,600);
	//绑定信号
	connect(openBtn, SIGNAL(clicked()), this, SLOT(openSlot()));
	connect(saveBtn, SIGNAL(clicked()), this, SLOT(saveSlot()));
}
//槽函数
void myImage::openSlot()
{
	//获取文件名字
	QString str = QFileDialog::getOpenFileName(this, "打开文件", "/", "All File(*.*)");
	//加载图片
	image.load(str);
	update();
}
//槽函数
void myImage::saveSlot()
{
	bool ok;
	//获取输入的信息
	QString str = QInputDialog::getText(this, "输入对话框", "请输入名字", QLineEdit::Normal, "wj", &ok);

	//保存图像
	image.save(str + ".png");
}
void myImage::paintEvent(QPaintEvent *e)
{
	QPainter p(this);
	p.drawImage(100,100,image);
}
